// ignore_for_file: file_names, must_be_immutable, constant_identifier_names, slash_for_doc_comments, avoid_unnecessary_containers, prefer_const_constructors, unnecessary_cast, sized_box_for_whitespace, prefer_function_declarations_over_variables, overridden_fields, annotate_overrides, prefer_const_literals_to_create_immutables, unnecessary_null_comparison, deprecated_member_use

import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:mybase/base/config/ColorConfig.dart';
import 'package:mybase/base/config/DeaultPageConfig.dart';
export 'package:mybase/base/widget/layout/FFImageFactory.dart';

final RouteObserver<PageRoute> routeObserver = RouteObserver<PageRoute>();

/**页面状态 */
enum FFPageStatus {
  firstLoading, //首次进入
  noData, //空数据
  netError, //网络错误
  result, //结果页:显示正常UI
}

/**抽象类 */
abstract class IFFScaffold {
  /**页面样式 */
  FFScaffoldStyle? ffStyle;

  /**页面状态 */
  FFPageStatus? ffPageStatus;

  Orientation? orientation;

  /**当有tabbar时，子页面距离tabbar底部有区域会影响点击事件，得设置为true*/
  bool? ffTabbarRemoveTop;

  /**页面边距参数*/
  FFPageSpacingParam? ffPageSpacingParam;

  /**生命周期方法 */
  void ffInitState();

  void ffDidChangeDependencies();

  void ffDispose();

  /**生命周期方法END */

  Widget? ffBottomNavigationBar(BuildContext context);

  /**导航栏 */
  Widget? ffNavi(BuildContext context);

  /**导航栏下 固定区域*/
  Widget? ffNaviBottomFixedArea(BuildContext context);

  //如果碰到页面底部有一个单位的间隙，使用此decoration
  /*
    @override
  Widget? ffBottom(BuildContext context) {
    return Container(
      decoration: BoxDecoration(
        boxShadow: const [
          BoxShadow(
            color: Colors.white,
            blurRadius: 0.0,
            spreadRadius: 2.0,
          )
        ],
        color: Colors.white,
      ),
    );
  }
   */
  /**body */
  Widget? ffBody(BuildContext context);

  /**web body */
  Widget? ffBodyWeb(BuildContext context);

  /**底部 */
  Widget? ffBottom(BuildContext context);

  /**首次进入加载页面 */
  Widget? ffFirstLoadingWidget(BuildContext context);

  /**空数据页面 */
  Widget? ffNoDataWidget(BuildContext context, {FFEventObj? obj});

  /**网络错误页面 */
  Widget? ffNetErrorWidget(BuildContext context, {FFEventObj? obj});

  ScrollPhysics? physics;

  Widget? ffloatingActionButton(BuildContext ctx);
}

/**默认实现页 */
class MFFScaffold implements IFFScaffold {
  @override
  Widget? ffNavi(BuildContext context) {}

  @override
  Widget? ffNaviBottomFixedArea(BuildContext context) {}

  @override
  Widget? ffBody(BuildContext context) {}

  @override
  Widget? ffBodyWeb(BuildContext context) {}

  @override
  Widget? ffBottom(BuildContext context) {}

  @override
  void ffInitState() {
    ffStyle?.ffBodyColor = ColorConfig().bodyColor;
    ffStyle?.ffStatusBackgroundColor = ColorConfig().statusBackgroundColor;
    ffStyle?.ffStatusTextColor = ColorConfig().statusTextColor;
  }

  @override
  void ffDidChangeDependencies() {}

  @override
  void ffDispose() {}

  @override
  FFScaffoldStyle? ffStyle = FFScaffoldStyle(
    ffStatusBackgroundColor: Colors.white,
    ffStatusTextColor: SystemUiOverlayStyle.dark,
    ffBodyColor: Colors.white,
  );

  @override
  FFPageStatus? ffPageStatus = FFPageStatus.firstLoading;

  @override
  Widget? ffFirstLoadingWidget(BuildContext context) {
    return DeaultPageConfig().ffFirstLoadingWidget;
  }

  @override
  Widget? ffNetErrorWidget(BuildContext context, {FFEventObj? obj}) {
    if (DeaultPageConfig().ffNetErrorFunc != null) {
      return DeaultPageConfig().ffNetErrorFunc!(obj);
    }
    return null;
  }

  @override
  Widget? ffNoDataWidget(BuildContext context, {FFEventObj? obj}) {
    if (DeaultPageConfig().ffNoDataFunc != null) {
      return DeaultPageConfig().ffNoDataFunc!(obj);
    }
    return null;
  }

  @override
  ScrollPhysics? physics;

  @override
  Widget? ffloatingActionButton(BuildContext ctx) {
    return null;
  }

  @override
  Widget? ffBottomNavigationBar(BuildContext context) {
    return null;
  }

  @override
  FFPageSpacingParam? ffPageSpacingParam;

  @override
  Orientation? orientation = Orientation.portrait;

  @override
  bool? ffTabbarRemoveTop = false;

}

/**页面样式 */
class FFScaffoldStyle {
  /**
   * 状态栏背景颜色，
   * 默认白色,
   * 导航栏没有设置颜色，则会跟随此颜色
   */
  Color? ffStatusBackgroundColor;

  /**状态栏文字颜色，默认黑色 */
  SystemUiOverlayStyle? ffStatusTextColor;

  /**body,默认白色 */
  Color? ffBodyColor;

  /**显示状态栏,默认true:显示 */
  //bool? ffShowStatus;

  FFScaffoldStyle({
    this.ffBodyColor,
    this.ffStatusBackgroundColor,
    this.ffStatusTextColor,
    //this.ffShowStatus,
  });
}

class FFEventObj {
  Function? firstRefresh;

  FFEventObj({
    this.firstRefresh,
  });
}

class FFPageSpacingParam {
  bool? bottomSpacing;

  FFPageSpacingParam({
    this.bottomSpacing,
  });
}
